package uk.ac.bath.domains.misc;
//import  uk.ac.bath.engine.*;

import uk.ac.bath.legacy.Point;

public class Limited2DSpace extends Space2D {

    public Limited2DSpace(int sizeX, int sizeY) {
        super(sizeX, sizeY, 1);
    }

    public Point randomPointNear(Point p1, int rad) {
        Point2DInt p = rawRandomPointNear(p1, rad);
        if (p.x >= sizeX) {
            p.x = sizeX - 1;
        } else if (p.x < 0) {
            p.x = 0;
        }
        if (p.y >= sizeY) {
            p.y = sizeY - 1;
        } else if (p.y < 0) {
            p.y = 0;
        }

        return p;
    }

    public boolean contains(Point p) {
      //  Point2DInt p = (Point2DInt) p1;

        if (p.getIY() >= sizeY) {
            return false;
        } else if (p.getY() < 0) {
            return false;
        }

        if (p.getIX() >= sizeX) {
            return false;
        } else if (p.getX() < 0) {
            return false;
        }
        return true;
    }

    public Point above(Point p1) {
        Point2DInt p = (Point2DInt) p1;
        int y = p.getIY() - 1;
        if (y < 0) {
            return null;
        }
        int x = p.getIX();
        return new Point2DInt(x, y);
    }

    public Point below(Point p1) {
        Point2DInt p = (Point2DInt) p1;
        int y = p.getIY() + 1;
        if (y >= sizeY) {
            return null;
        }
        int x = p.getIX();

        return new Point2DInt(x, y);
    }

    public Point left(Point p1) {
        Point2DInt p = (Point2DInt) p1;
        int x = p.getIX() - 1;
        if (x < 0) {
            return null;
        }

        int y = p.getIY();
        return new Point2DInt(x, y);
    }

    public Point right(Point p1) {
        Point2DInt p = (Point2DInt) p1;
        int x = p.getIX() + 1;
        if (x >= sizeX) {
            return null;
        }
        int y = p.getIY();
        return new Point2DInt(x, y);
    }
}

